rm(list = ls())
setwd("/Users/John/Dropbox/")

# --- Load Required Packages ---
library(tidyverse)

# --- Load Data  ---
data <- as.data.frame(read_excel("JOP_Replication_Materials/appendix/data/cn_policies_strategic.xlsx", 
                                 sheet = "shortlist_strategic_industries")) 

# --- Prepare LaTeX table content ---
latex_table <- paste0(
  "\\begin{CJK*}{UTF8}{gbsn}\n",  # Begin the CJK environment
  "\\singlespacing\n",
  "{\\fontsize{8}{10}\\selectfont\n",
  "\\begin{longtable}{|p{4.2cm}|p{6.8cm}|p{2cm}|}\n",
  "\\caption{Industries Targeted by Chinese Industrial Policy Initiatives} \\label{tab:policy-industries} \\\n",
  "\\hline\n",
  "\\textbf{Industry (Chinese)} & \\textbf{Industry (English)} & \\textbf{Policy} \\\\\n",
  "\\hline\n",
  "\\endfirsthead\n",
  "\n",
  "\\hline\n",
  "\\textbf{Industry (Chinese)} & \\textbf{Industry (English)} & \\textbf{Policy} \\\\\n",
  "\\hline\n",
  "\\endhead\n",
  "\n",
  "\\hline\n",
  "\\multicolumn{3}{r}{\\textit{Continued on next page}} \\\n",
  "\\endfoot\n",
  "\n",
  "\\hline\n",
  "\\endlastfoot\n"
)

# --- Add data rows ---
for(i in 1:nrow(data)) {
  latex_table <- paste0(latex_table, 
                        data$industry_cn[i], " & ",
                        data$industry_eng[i], " & ",
                        data$policy[i], " \\\\\n")
}

# --- Close LaTeX table ---
latex_table <- paste0(latex_table, "\\end{longtable}\n", "}\n")
latex_table <- paste0(latex_table, "\\end{CJK*}\n")

# --- Save Table ---
writeLines(latex_table, "JOP_Replication_Materials/appendix/output/B_table_2.tex")









